package com.mas.session.state;

import jade.domain.FIPAException;
import jade.lang.acl.ACLMessage;

import com.mas.session.Session;
import com.mas.strategey.Proposal;

/**
 * @author Dudi & Efi
 * 
 */
public abstract class AbstractState {

	protected Session session;
	protected Proposal proposal;

	public AbstractState() {
		super();
	}

	/**
	 * @param session
	 */
	public AbstractState(Session session) {
		super();
		setup(session);
	}

	public void setup(Session session) {
		this.session = session;
	}

	public void processIncomingCFPMsg(ACLMessage message) throws FIPAException {
		throwNoStatTransitionAllowed();
	}

	public void notUnderstandMsgContent(ACLMessage message, String reason)
			throws FIPAException {
		throwNoStatTransitionAllowed();
	}

	public void waitForProposalResponse(ACLMessage message)
			throws FIPAException {
		throwNoStatTransitionAllowed();
	}

	public void NoAvailableResource(ACLMessage message) {
		throwNoStatTransitionAllowed();
	}

	public void acceptProposalResponse(ACLMessage message) throws FIPAException {
		throwNoStatTransitionAllowed();
	}

	public void rejectProposalResponse(ACLMessage message) throws FIPAException {
		throwNoStatTransitionAllowed();
	}

	public void acceptProposalError(ACLMessage message) throws FIPAException {
		throwNoStatTransitionAllowed();
	}

	public void proposalAccepted(ACLMessage message) throws FIPAException {
		throwNoStatTransitionAllowed();
	}

	public void processNewProposal(ACLMessage message)  {
		throwNoStatTransitionAllowed();
	}
	public void offerNewProposal(ACLMessage message)  {
		throwNoStatTransitionAllowed();
	}
	
	
	
	private void throwNoStatTransitionAllowed() {
		throw new RuntimeException("No Stat Transition Allowed");
	}

	protected void assignFailureState(ACLMessage message, String reason) {
		FailureExit state = (FailureExit) this.session
				.assignState(FailureExit.class.getName());
		state.notUnderstandMsgContent(message, reason);
	}

	/**
	 * @return the proposal
	 */
	public Proposal getProposal() {
		return proposal;
	}

	/**
	 * @param proposal the proposal to set
	 */
	public void setProposal(Proposal proposal) {
		this.proposal = proposal;
	}

}
